﻿Public Class clsMessage
    Public isCheckMessageUnread As Boolean = False
    Public DictMessageUnread As New Dictionary(Of String, objMessageReceived)
    Public MessageComposer As New clsMessageComposer

    Public Sub getMessageUnread()
        If frmMain.Account.Login.infoLogin.FacebookID > 0 Then
            If (frmMain.Account.Login.infoLogin.AccessToken <> "") Then
                If isCheckMessageUnread = False Then
                    Dim f As clsMessageUnread
                    f = New clsMessageUnread(frmMain, frmMain.Account.Login.infoLogin)
                    Dim thread As New Threading.Thread(AddressOf f.getUnread)
                    thread.Start()
                End If
            Else
                Debug.Print("Don't have access_token")
                frmMain.Account.AccessToken.getAccessToken()
            End If
        End If
    End Sub

    Public Function getMessageContentSendUnread(ByVal ContentReceive)
        Dim DictSend As New Dictionary(Of String, String)
        DictSend.Add("hello", "hello cai gi")
        DictSend.Add("hello1", "hello cai gi 1")
        DictSend.Add("alo", "khong co nghe")
        DictSend.Add("TRINM", "khong co nghe TRINM")
        For Each item In DictSend
            If (InStr(ContentReceive, item.Key, CompareMethod.Text) > 0) Then
                Return item.Value.ToString
            End If
        Next
        Return "Khong tim thay noi dung tra loi"
    End Function

    Public Sub MessageComposerUnread_Success(ByVal objMessage As objMessageComposer)
        Dim i As Integer
        Dim receive As String
        If (objMessage IsNot Nothing) Then
            receive = objMessage.ListReceive(0)
            For i = 0 To frmMain.lstMessageUnread.Items.Count - 1
                If (frmMain.lstMessageUnread.Items(i).SubItems(3).Text = receive) Then
                    frmMain.lstMessageUnread.Items(i).Remove()
                    frmMain.MessageFB.DictMessageUnread.Remove(receive)
                End If
            Next
        End If

    End Sub
End Class
